<!--
 * @Description:查看反馈
 * @Author:zhangweigang
 * @Date: 2021-02-14 20:08:05
 * @LastEditTime: 2021-04-22 19:46:33
 * @LastEditors: zhangweigang
-->
<template>
  <div>
    <Header></Header>
    <curr-locat title="查看反馈"></curr-locat>
    <div class="contain">
      <div v-if="myStoreInfo.length > 0">
        <div class="item" v-for="(item, index) in myStoreInfo" :key="index">
          <div class="leave-msg btf_space">
            <div class="left l">
              <h3>{{ item.username }}</h3>
              <p>#{{ item.commentDate }}</p>
            </div>
            <div class="right r">
              <div class="info">{{ item.content }}</div>
            </div>
            <div class="reply bt">
              <a @click="lookReplyInfo(item.id)">查看</a>
            </div>
          </div>
        </div>
      </div>
      <div class="no-info" v-else>暂无回复，请等待...</div>
    </div>
    <!-- 查看回复弹窗框 -->
    <el-dialog title="查看回复" :visible.sync="dialogLookVisible">
      <div v-if="l > 0">
        <div class="btf_space" v-for="(subItem, index) in replayList" :key="index">
          <div class="left l">
            <h3 class="lb">{{ subItem.username }}</h3>
            <div class="touser lb">回复</div>
            <h3 class="lb">{{ subItem.toUsername }}</h3>
            <p>#{{ subItem.replyDate }}</p>
          </div>
          <div class="r right">
            <div class="info">{{ subItem.content }}</div>
          </div>
          <div class="reply bt">
            <button @click="replyInfoParams(subItem.commentId, subItem.id, subItem.toUserId, subItem.toUsername, subItem.userId, subItem.username)">回复</button>
          </div>
        </div>
      </div>
      <div class="no-info" v-else>这条留言暂无回复！请等待...</div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogLookVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogLookVisible = false">确 定</el-button>
      </div>
    </el-dialog>
    <!-- 回复消息弹出框 -->
    <el-dialog title="消息回复" :visible.sync="dialogReylayVisible">
      <el-form :model="replyForm" :rules="replyRules" ref="replyRef" class="demo-ruleForm">
        <el-form-item label="回复内容" prop="content">
          <el-input type="textarea" :rows="6" v-model="replyForm.content"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="resetReply">取 消</el-button>
        <el-button type="primary" @click="confirmInfo">确 定</el-button>
      </div>
    </el-dialog>
    <Footer></Footer>
  </div>
</template>

<script>
import { getSoleReplayInfo, getLeaveInfoData, replyLeaveInfo } from '../../network/product.js';
export default {
  data() {
    return {
      dialogReylayVisible: false,
      dialogLookVisible: false,
      // 回复表单
      replyForm: {
        content: ''
      },
      replyRules: {
        content: [{ required: true, message: '回复内容不能为空！', trigger: 'blur' }]
      },
      currentUser: localStorage.getItem('username'),
      isShowFeed: false, // 是否显示回复留言信息
      myStoreInfo: [], // 保存当前user我的留言信息
      replayList: [], // 回复的数据列表
      l: 0
    };
  },
  created() {
    // 获取所用用户留言筛选出当前用户留言信息
    this.getAllLeaveData();
  },
  methods: {
    // 获取所用用户留言筛选出当前用户留言信息
    getAllLeaveData() {
      let self = this;
      getLeaveInfoData().then((res) => {
        if (res.data.code === 0 && res.status === 200) {
          // 筛选出当前用户的留言 id 为 commentId
          res.data.rows.map((item) => {
            if (item.username === localStorage.getItem('username')) {
              self.myStoreInfo.push(item);
            }
          });
          console.log(self.myStoreInfo, '当前用户的留言信息');
        } else {
          self.$message({
            showClose: true,
            message: '获取我的留言失败，请联系管理员！',
            type: 'error',
            duration: 4000
          });
        }
      });
    },
    // 查看回复
    lookReplyInfo(commentId) {
      this.$router.push('/feedlist/' + commentId);
    },
    /**
     * 接收参数
     * @params commentId 内容ID
     * @params replayId 回复ID
     */
    replyInfoParams(commentId, replyId, toUserId, toUsername, userId, username) {
      this.dialogLookVisible = false;
      this.dialogReylayVisible = true;
      this.replyForm = {
        commentId: commentId,
        replyId: replyId,
        toUserId: userId,
        toUsername: username,
        userId: toUserId,
        username: toUsername,
        delFlag: 1, // 未删除
        replyType: 2, // 给回复的回复
        sysRoleId: 0, // 必传参数，无需理会
        sysRoleName: '' // 必传参数，无需理会
      };
    },
    // 确定回复
    confirmInfo() {
      console.log(this.replyForm, '提交参数');
      this.$refs.replyRef.validate((valid) => {
        if (valid) {
          replyLeaveInfo(this.replyForm).then((res) => {
            if (res.data.code === 0 && res.status === 200) {
              this.dialogReylayVisible = false;
              this.$message({
                showClose: true,
                message: '恭喜您，回复成功！请等待...',
                type: 'success',
                duration: 4000
              });
            } else {
              this.$message({
                showClose: true,
                message: '回复失败，请联系管理员！',
                type: 'error',
                duration: 4000
              });
            }
          });
        } else {
          this.$message({
            showClose: true,
            message: '请先输入内容！',
            type: 'error',
            duration: 4000
          });
          return false;
        }
      });
    },
    resetReply() {
      this.$refs.replyRef.resetFields();
      this.dialogReylayVisible = false;
    }
  }
};
</script>

<style lang="less" scoped>
.contain {
  position: relative;
}
.btf_space {
  display: flex;
  align-items: center;
  padding: 10px;
  border-top: 1px solid #c1bcbc;
}
.lb {
  display: inline-block;
}
.l {
  width: 175px;
  height: auto;
  color: #999;
  h3 {
    color: #333;
  }
}
.r {
  flex: 1;
  height: auto;
}
.bt {
  width: 80px;
  text-align: center;
}
.left {
  p {
    font-weight: bold;
    font-size: 14px;
    font-family: Sentinel SSm A, Sentinel SSm B, system-ui, -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Helvetica, Arial, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol;
  }
}
.right {
  padding: 10px;
  background: #f3f3f3;
  border-radius: 5px;
}
.info {
  width: 100%;
  height: auto;
  color: #333;
  font-size: 16px;
  font-family: '微软雅黑';
  letter-spacing: 1px;
}
.reply {
  a {
    color: red;
    font-size: 14px;
    cursor: pointer;
    &:hover {
      text-decoration: underline;
    }
  }
}
.pagin {
  margin-top: 15px;
}
.touser {
  padding: 0 5px;
  font-size: 15px;
  font-weight: bold;
  color: #333;
}
.no-info {
  text-align: center;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 7px;
  color: #999;
}
</style>
